<?php
/* @var $this SuratKeluarController */
/* @var $model SuratKeluar */
/* @var $form CActiveForm */
?>
<?php $this->beginWidget('ext.widgets.XPanel', array('title' => 'Surat Keluar', 'width' => 900,'height' => 500)); 
?>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'surat-keluar-form',
	'enableAjaxValidation'=>false,
        //'enableClientValidation'=>true,
        'clientOptions'=>array(
                //'validateOnSubmit'=>true,
                //'beforeValidate' => 'js:beforeValidate'
        ),
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>
    <table class="ma-table">
        <tbody>
        <tr>
		<td class="labelfield" style="width:200px">
                    <?php echo CHtml::label('Ditulis Oleh :', ''); ?>
                </td>
		<td>
                    <?php echo CHtml::activeTextField($model->SuratKeluar->Pegawai, 'nama', array('readonly'=>'readonly')); ?>
                </td>
		<td>
                </td>
	</tr>    
	<tr>
		<td class="labelfield" style="width:200px">
                    <?php echo $form->labelEx($model->SuratKeluar, 'no_surat'); ?>
                </td>
		<td>
                    <?php echo CHtml::activeTextField($model->SuratKeluar, 'no_surat', array('readonly'=>'readonly')); ?>
                </td>
		<td>
                    <?php echo $form->error($model->SuratKeluar, 'no_surat'); ?>
                </td>
	</tr>
        
	<tr>
		<td class="labelfield" style="width:200px">
                    <?php echo $form->labelEx($model->SuratKeluar,'nama_tipe_surat'); ?>
                </td>
		<td>
                    <?php 
                        echo CHtml::activeDropDownList(
                                $model->SuratKeluar,
                                'id_tipe_surat',
                                CHtml::listData(
                                        TipeSurat::model()->findAll(), 
                                        'id_tipe_surat', 
                                        'nama_tipe_surat'
                                        )
                                , 
                                array('readonly'=>'readonly')
                                
                                ); 
                    ?>
                </td>
		<td><?php echo $form->error($model->SuratKeluar,'id_tipe_surat'); ?>
</td>
	</tr>
        
	<tr>
		<td class="labelfield" style="width:200px">
                    <?php echo $form->labelEx($model->SuratKeluar,'judul_surat'); ?>
                </td>
		<td>
                    <?php echo CHtml::activeTextField($model->SuratKeluar,'judul_surat',array('readonly'=>'readonly')); ?>
                </td>
		<td>
                    <?php echo $form->error($model->SuratKeluar,'judul_surat'); ?>
                </td>
	</tr>
        <tr>
		<td class="labelfield" style="width:200px">
                    <?php echo $form->labelEx($model->SuratKeluar,'isi_surat'); ?>
                </td>           
                <td>
                    <?php echo substr( strip_tags($model->SuratKeluar->isi_surat), 0, 500) ?>
                    <br/><br/>
                    <?php
                        echo CHtml::link(
                                'Print Preview', 
                                array('SuratKeluar/preview/'.$model->SuratKeluar->id_surat_keluar),
                                array('target'=>'blank')
                                );
                    ?>
                   
                </td>
		<td>
                    <?php echo $form->error($model->SuratKeluar,'isi_surat'); ?>
                </td>
	</tr>
        <tr>
            <td colspan="3">
                
                <fieldset>
                    <legend>Daftar Persetujuan</legend>
                   
                <div class="grid-view" id="pegawai-grid">
                            <div style="height:17px;border:0px;" class="x-panel-header-default x-horizontal x-panel-header-horizontal x-panel-header-default-horizontal x-top x-panel-header-top x-panel-header-default-top x-docked-top x-panel-header-docked-top x-panel-header-default-docked-top x-unselectable">                    
                                <span class="x-panel-header-text x-panel-header-text-default">                                            
                                </span>
                            </div>
                            <div class="ax-body-panel">
                                    <div style="clear: both;"></div>
                                    <table class="items" id="pegawai_table">
                                        <thead>
                                            <tr>
                                                <th id="pegawai-grid_c1">
                                                    Nama Pegawai
                                                </th>
                                                <th id="pegawai-grid_c2">
                                                    Unit
                                                </th>
                                                <th>
                                                    Status
                                                </th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                                foreach($model->SuratKeluar->PersetujuanSuratKeluar as $key=>$value){
                                            ?>
                                            <tr>
                                                <td><?php echo $value->Pegawai->nama?></td>
                                                <td>
                                                    <?php echo $value->Pegawai->Jabatan->StrukturOrganisasi->nama?> 
                                                    (<?php echo $value->Pegawai->Jabatan->nama?>)
                                                </td>
                                                <td>
                                                    <?php 
                                                        if($value->setuju=='1')
                                                            echo 'Setuju';
                                                        elseif($value->setuju=='0')
                                                            echo 'Tolak';
                                                        else
                                                            echo 'Menunggu';
                                                    ?>
                                                </td>
                                            </tr>
                                            <?php
                                                }
                                            ?>
                                        </tbody>
                                    </table>
                            </div><div title="/index.php?r=Pegawai" style="display:none" class="keys"><span>1</span><span>2</span><span>3</span><span>4</span><span>5</span></div>
                        </div>
                    Urutan Pegawai yang paling atas akan didahulukan terlebih dahulu.
                </fieldset>
                
            </td>
            
        </tr>

	<tr>
		<td></td>
                <td>
                    <?php 
                    if($approved>0){
                        echo CHtml::submitButton('Approve', array('class'=>'ax-btn', 'id'=>'approve'))." "; 

                        echo CHtml::Button('Tolak', 
                                array(
                                    'class'=>'ax-btn-delete',
                                    'onclick'=>'$("#mydialog").dialog("open"); return false;'
                                    )
                                );
                    }else{
                    ?>
                    <h3>Surat ini sudah di setujui oleh</h3>
                    <?php
                    }
                    ?>
                </td>
                <td></td>
	</tr>
        </tbody>
    </table>
<?php 
$this->endWidget();  // form
?>

</div><!-- form -->
<?php $this->endWidget(); ?>


<?php


                    $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
                        'id'=>'mydialog',
                        // additional javascript options for the dialog plugin
                        'options'=>array(
                            'title'=>'Alasan Penolakan',
                            'autoOpen'=>false,
                        ),
                    ));
                    
                    $form2=$this->beginWidget('CActiveForm', array(
                            'id'=>'surat-keluar-form2',
                            'enableAjaxValidation'=>true,
                            //'enableClientValidation'=>true,
                            'clientOptions'=>array(
                                    'validateOnSubmit'=>true,
                                    //'beforeValidate' => 'js:beforeValidate'
                            ),
                    )); 
                    
                    echo CHtml::activeTextArea(
                                        $model, 
                                        'alasan_penolakan', 
                                        array(
                                            'style'=>'width:100%', 
                                            'cols'=>30, 
                                            'rows'=>5
                                            )
                                )."<br/><br/>";
                    echo CHtml::submitButton('Submit', array('class'=>'ax-btn-delete', 'id'=>'tolak_submit'))." "; 
                    echo CHtml::Button('Cancel', array('class'=>'ax-btn', 'id'=>'cancel')); 
                    
                    $this->endWidget();
                        
                    $this->endWidget('zii.widgets.jui.CJuiDialog');
                    
                    
                    Yii::app()->clientScript->registerScript(
                            'penerimaan-tamu-form-beforeValidate', 
                            "
                            $('#cancel').click(function(){ 
                                $('#PersetujuanSuratKeluar_alasan_penolakan').val('');
                                $('#mydialog').dialog('close'); 
                            });

                            $('#tolak_submit').click(function(){
                                if($('#PersetujuanSuratKeluar_alasan_penolakan').val()!=''){
                                    $('#surat-keluar-form2').submit();
                                }else{
                                    alert('Alasan Penolakan masih kosong');
                                    return false;
                                }
                            });"
                            );

